<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>CREATE EVENT</title>
    <script language="javascript" type="text/javascript">
		function Month()
		{
			var thang1 = document.getElementById("Thang1");
			var option = new Option("Tháng","");
			thang1.options[0] = option;
			var k = 1;
			for(i=1; i<13; i++)
			{
				if(i<10)
				{
					str = "0" + i;
				}
				else
				{
					str = i;
				}
				var option = new Option(str,str);
				thang1.options[k] = option;
				k++;
			}
			
			var thang2 = document.getElementById("Thang2");
			var option = new Option("Tháng","");
			thang2.options[0] = option;
			var k = 1;
			for(i=1; i<13; i++)
			{
				if(i<10)
				{
					str = "0" + i;
				}
				else
				{
					str = i;
				}
				var option = new Option(str,str);
				thang2.options[k] = option;
				k++;
			}
		}
		function Year()
		{
			var nam1 = document.getElementById("Nam1");
			var option = new Option("Năm","");
			nam1.options[0] = option;
			var currentTime = new Date()	
			var year1 = currentTime.getFullYear()
			var k = 1;
			for(i=year1; i>1900; i--)
			{
				var option = new Option(i,i);
				nam1.options[k] = option;
				k++;
			}
			
			var nam2 = document.getElementById("Nam2");
			var option = new Option("Năm","");
			nam2.options[0] = option;
			var currentTime = new Date()	
			var year2 = currentTime.getFullYear()
			var k = 1;
			for(i=year2; i>1900; i--)
			{
				var option = new Option(i,i);
				nam2.options[k] = option;
				k++;
			}
		}
		function tinhngay()
		{
			var nam1 = document.getElementById('Nam1');
			var yea1r = parseInt(nam1.options[nam1.selectedIndex].text);
			if((year1%4==0&&year1%100!=0)||(year1%400==0))
			{
				return 30;
			}
			return 29;	
			
			var nam2 = document.getElementById('Nam2');
			var year2 = parseInt(nam2.options[nam2.selectedIndex].text);
			if((year2%4==0&&year2%100!=0)||(year2%400==0))
			{
				return 30;
			}
			return 29;
		}
		function Day()
		{
			var ngay1 = document.getElementById('Ngay1');
			var thang1 = document.getElementById('Thang1');
			var nam1 = document.getElementById('Nam1');
			if(thang1.selectedIndex==2)
			{		
				ngay1.length = tinhngay();
			}
			else
			{
				if(thang1.selectedIndex==1 || thang1.selectedIndex==3 || thang1.selectedIndex==5 || thang1.selectedIndex==7 || thang1.selectedIndex==8 || thang1.selectedIndex==10 || thang1.selectedIndex==12)
				{
					ngay1.length=32;
				}
				else
				{
					ngay1.length=31;
				}
			}
			var option = new Option("Ngày","");
			ngay1.options[0] = option;
			var k=1;
			for(var i=2; i<=ngay1.length; i++)
			{
				if(i<10)
				{
					str = "0" + (i-1);
				}
				else
				{
					str = (i-1);
				}
				var option = new Option(str,str);
				ngay1.options[i-1] = option;
				k++;
			}
			
			var ngay2 = document.getElementById('Ngay2');
			var thang2 = document.getElementById('Thang2');
			var nam2 = document.getElementById('Nam2');
			if(thang2.selectedIndex==2)
			{		
				ngay2.length = tinhngay();
			}
			else
			{
				if(thang2.selectedIndex==1 || thang2.selectedIndex==3 || thang2.selectedIndex==5 || thang2.selectedIndex==7 || thang2.selectedIndex==8 || thang2.selectedIndex==10 || thang2.selectedIndex==12)
				{
					ngay2.length=32;
				}
				else
				{
					ngay2.length=31;
				}
			}
			var option = new Option("Ngày","");
			ngay2.options[0] = option;
			var k=1;
			for(var i=2; i<=ngay2.length; i++)
			{
				if(i<10)
				{
					str = "0" + (i-1);
				}
				else
				{
					str = (i-1);
				}
				var option = new Option(str,str);
				ngay2.options[i-1] = option;
				k++;
			}
		}
	</script>
</head>

<body onload="Year(); Month(); Day();">
	<h2 align="center">CREATE EVENT</h2>
    	<form id="createCourse" action="../createEventExecute.php" method="post">
            <table bordercolor="#00CCCC" align="center">
                <tr>
                	<td>Start Date</td>
                    <td align="left">
                        <select id="Ngay1">
                        </select>* 
                        -
                        <select id="Thang1" onchange="Day();">
                        </select>*
                        -
                        <select id="Nam1" onchange="Day();">
                        </select>* ( DD / MM / YYYY ) 
                	</td>
                </tr>
                <tr>
                	<td>Finish Date</td>
                    <td align="left">
                        <select id="Ngay2">
                        </select>* 
                        -
                        <select id="Thang2" onchange="Day();">
                        </select>*
                        -
                        <select id="Nam2" onchange="Day();">
                        </select>* ( DD / MM / YYYY ) 
                	</td>
                </tr>
                <tr align="center">
                    <td colspan="2"><input type="submit" value="Khởi Tạo" style="background-color:#CCCCCC" /></td>
                </tr>
        	</table>
        </form>
</body>
</html>